@extends('layouts.back_stage')
@section('content')
    <style>
        .shopBg{background:#fff;overflow: hidden;margin:0 0 10px 0;}
        .tableBg{padding:30px;background:#fff;}
        .input-item{width:350px;padding-right: 0;margin-right:10px;}
        .input-info{width:350px;padding-right: 0;margin-right:10px;}
        .pagination-box{text-align: center;box-sizing:border-box;margin-top:20px;}
        .el-range-editor--small.el-input__inner{width:300px;}
        .el-date-editor .el-range-separator{padding:0 15px}

        .infoTopDiv{margin-top:10px;padding:10px 30px;height:55px;background:#fff;}
        .infoTopDiv span{margin-right:50px;}
        .infoDiv{float:left;line-height:31px;}
        .infoDiv span{margin-right:50px;}
        .countInfo.el-table--mini th{padding:0;}
        ::-webkit-scrollbar {height: 8px;}
        .el-table__footer-wrapper tbody td, .el-table__header-wrapper tbody td{color:red;}
        [v-cloak] {display: none;}
    </style>
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;"><h3 style="float:left;">扫码退货单</h3></div>
        <!-- 主体-->
        <div class="page-body">
            <audio id="music_success" src="{{env('CDN_DOMAIN_NAME')}}/store/mp3/success.mp3" type="audio/mp3"></audio>
            <audio id="music_faile" src="{{env('CDN_DOMAIN_NAME')}}/store/mp3/faile.mp3" type="audio/mp3"></audio>
            <div class="row app" id="TiaoHuo" v-cloak>
                <div class="col-md-12 row row-table-box">
                    <div class="shopBg">
                        <div class="row" style="padding:10px 30px;background:#fff;margin-top:10px;">
                            <label style="margin-right:3px;">单 据 号：</label>
                            <el-input v-model="order_num" class="input-info" placeholder="单据号" size="small" :disabled="true"></el-input>
                            <label>退货仓库：</label>
                            <el-select v-model="fact_type_id" class="input-info" filterable placeholder="请选择退货仓库(必)" size="small" :disabled="sendType">
                                <el-option v-for="item in options1" :key="item.id" :label="item.factory_type" :value="item.id"></el-option>
                            </el-select>
                        </div>
                        <div class="row" style="padding:10px 30px;background:#fff;">
                            <label style="margin-right:22px;">类 别：</label>
                            <el-radio-group v-model="customer_type" size="small" style="width:360px;" :disabled="sendType" @change="radioCha">
                                <el-radio label="2" border>客户</el-radio>
                                <el-radio label="1" border>店铺</el-radio>
                            </el-radio-group>
                            <div style="display: inline-block;" v-show="shopShow">
                                <label>退货店铺：</label>
                                <el-select v-model="customer_id" class="input-item" filterable placeholder="请选择退货店铺(必)" size="small" :disabled="sendType">
                                    <el-option v-for="item in options2" :key="item.id" :label="item.shop_name" :value="item.id"></el-option>
                                </el-select>
                            </div>
                            <div style="display: inline-block;" v-show="peopleShow">
                                <label>客户名称：</label>
                                <el-select v-model="customer_id" class="input-item" filterable placeholder="请选择客户(必)" size="small" :disabled="sendType">
                                    <el-option v-for="item in options4" :key="item.id" :label="item.customer_name" :value="item.id"></el-option>
                                </el-select>
                            </div>
                        </div>
                        <div class="row" style="padding:10px 30px;background:#fff;margin-bottom:10px;">
                            <label>销售季节：</label>
                            <el-select v-model="season_id" class="input-item" filterable placeholder="请选择销售季节(必)" @change="changeLabel" size="small" :disabled="sendType">
                                <el-option v-for="item in options3" :key="item.id" :label="item.sale_season" :value="item.id"></el-option>
                            </el-select>
                            <label>退货类型：</label>
                            <el-select v-model="deliver_type_id" class="input-item" filterable placeholder="请选择发货类型(必)" size="small" :disabled="sendType">
                                <el-option v-for="item in options5" :key="item.id" :label="item.name" :value="item.id"></el-option>
                            </el-select>
                        </div>
                        <div class="row" style="padding:10px 30px;background:#fff;margin-bottom:10px;">
                            <label style="float:left;margin-right:25px;">备 注：</label>
                            <el-input v-model="remark" border="0" style="width:785px;display:inline-block;" class="lis-textarea" type="textarea" :disabled="sendType" :autosize="{ minRows: 1, maxRows: 350}" maxlength="30" placeholder="请填写备注(30以内字符)"></el-input>
                        </div>
                    </div>
                    <div class="shopBg shows">
                        <div class="row" v-show="souType" style="padding:30px;height:90px;background:#fff;">
                            <label style="margin-bottom:0;">请扫描条码：</label>
                            <el-input v-model.trim="codes" class="input-item" placeholder="请扫描或输入" size="small" prefix-icon="el-icon-search" clearable></el-input>
                            <el-button type="primary" size="small" @click="sureCode">确认</el-button>
                        </div>
                        <div class="row" style="padding:30px;height:90px;background:#fff;">
                            <label>请输入条码：</label>
                            <el-input v-model.trim="small_qr" class="input-item" placeholder="请输入" size="small" prefix-icon="el-icon-search" clearable></el-input>
                            <label>请输入款号：</label>
                            <el-input v-model.trim="girard" class="input-item" placeholder="请输入" size="small" prefix-icon="el-icon-search" clearable></el-input>
                            <el-button type="primary" size="small" @click="grabble('reset')">搜索</el-button>
                            <el-button type="primary" size="small" @click="resetSou('reset')">重置</el-button>
                        </div>
                    </div>
                    <div class="tableBg">
                        <h5>汇总</h5>
                        <el-table class="countInfo" :data="countInfo" size="mini" border style="width: 100%;" @filter-change="filterChange1" :summary-method="getSummaries" show-summary>
                            <el-table-column type="index" width="50" label="序号" :resizable='false'></el-table-column>
                            <el-table-column prop="brand_1" label="品牌" width="90" :resizable='false' column-key="brand_1" :filters="[{ text: 'Soyyos', value: '1' },{ text: 'SoonWord', value: '2' },{ text: '个么', value: '3' },{ text: '雏鸽', value: '4' },{ text: '听画', value: '5' },{ text: '听图', value: '6' },{ text: '欧年', value: '7' },{ text: '九两', value: '8' }]"></el-table-column>
                            <el-table-column prop="girard" label="款号" min-width="100" :resizable='false'></el-table-column>
                            <el-table-column prop="cate_3" label="小类" min-width="100" :resizable='false'></el-table-column>
                            <el-table-column prop="color" label="颜色" min-width="70" :resizable='false'></el-table-column>

                            <el-table-column v-for="item in sizeGr"  :label="item.key76" width="70" :resizable='false'>
                                <el-table-column :label="item.key75" width="70" :resizable='false'>
                                    <el-table-column :label="item.key79" width="70" :resizable='false'>
                                        <el-table-column :label="item.key154" width="70" :resizable='false'>
                                            <el-table-column :label="item.key146" width="70" :resizable='false'>
                                                <el-table-column :label="item.key161" width="70" :resizable='false'>
                                                    <el-table-column :label="item.key77" width="70" :resizable='false'>
                                                        <el-table-column :prop="item.key_0" :label="item.key140" width="70" :resizable='false'></el-table-column>
                                                    </el-table-column>
                                                </el-table-column>
                                            </el-table-column>
                                        </el-table-column>
                                    </el-table-column>
                                </el-table-column>
                            </el-table-column>

                            <el-table-column prop="count" label="合计/件" width="70" :resizable='false'></el-table-column>
                            <el-table-column prop="price" width="130" label="吊牌价/元" align="right" :resizable='false'></el-table-column>
                            <el-table-column prop="total_price" width="120" label="总计/元" align="right" :resizable='false'></el-table-column>
                        </el-table>
                    </div>
                    <div class="tableBg" style="margin-top:10px;">
                        <h5>扫码详情</h5>
                        <el-table :data="detailInfo" size="mini" border @filter-change="filterChange2">
                            <el-table-column prop="loop" label="序号" width="50" :resizable='false'></el-table-column>
                            <el-table-column prop="small_qr" label="条码" width="170" :resizable='false'></el-table-column>
                            <el-table-column prop="brand_2" label="品牌" width="100" :resizable='false' column-key="brand_2" :filters="[{ text: 'Soyyos', value: '1' },{ text: 'SoonWord', value: '2' },{ text: '个么', value: '3' },{ text: '雏鸽', value: '4' },{ text: '听画', value: '5' },{ text: '听图', value: '6' },{ text: '欧年', value: '7' },{ text: '九两', value: '8' }]"></el-table-column>
                            <el-table-column prop="girard" label="款号" width="110" :resizable='false'></el-table-column>
                            <el-table-column prop="cate_1" label="大类" :resizable='false'></el-table-column>
                            <el-table-column prop="cate_2" label="中类" :resizable='false'></el-table-column>
                            <el-table-column prop="cate_3" label="小类" :resizable='false'></el-table-column>
                            <el-table-column prop="color" width="90" label="颜色" :resizable='false'></el-table-column>
                            <el-table-column prop="size" width="60" label="尺码" :resizable='false'></el-table-column>
                            <el-table-column prop="price" width="100" label="吊牌价/元" align="right" :resizable='false'></el-table-column>
                            <el-table-column label="操作" width="50" fixed="right" :resizable='false'>
                                <template slot-scope="scope">
                                    <div v-if="scope.row.is_ack==='0'">
                                        <el-button type="text" size="small" @click="delSmallQr(scope)">删除</el-button>
                                    </div>
                                    <div v-else>
                                        <span>-</span>
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="pagination-box">
                            <el-pagination @current-change="changePageSkip2" :current-page="currentPage2" :total="total2" layout="prev, pager, next" background></el-pagination>
                        </div>
                        <div class="row" style="padding:13px 0;height:57px;background:#fff;">
                            <el-button style="float:right;" type="primary" v-show="souType" size="small" @click="overTrue">完成制单</el-button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /主体-->
    </div>
    <!-- /盘点记录-->
    <script>
        new Vue({
            el: '#TiaoHuo',
            data:{
                customer_type: '2',
                shopShow:false,
                peopleShow:true,

                sizeGr:[],//尺码信息
                is_ack:'{{$is_ack}}',
                options1: [],//退货仓库
                options2: [],//客 户
                options3: [],//销售季节
                options4: [],//客户
                options5: [],//退货类型

                order_num:'',//单据号
                fact_type_id:'',//退货仓库
                customer_id:'',//退货店铺or客户
                season_id:'',//销售季节id
                season:'',//销售季节名称
                deliver_type_id:'',//退货类型
                remark:'',//备注
                sendType:false,//退货仓库,收货店铺,销售季节,备注
                souType:true,//搜索,制单完成,扫描条码



                codes:'', //条形码
                brand_1:'',//汇总品牌搜索
                countInfo:[], //汇总
                small_qr:'',//搜索条码
                girard:'',//搜索款号
                brand_2:"", //详情品牌搜索
                detailInfo:[], //详情
                total2:1,  //详情总条数
                currentPage2:1, //详情当前页数

                girardNum:'',//款号种类合计

                delSmallQrFlag:true,
                overTrueFlag:true,
            },
            mounted(){
                if(this.is_ack==0){
                    this.sendType=false;
                    this.souType=true;
                }else if(this.is_ack==1){
                    this.sendType=true;
                    this.souType=false;
                }
                this.common();
                this.countBble();//汇总
                this.grabble();//详情
                this.basic();//仓库,客户，销售季节
            },
            methods:{
                /*尺码数据*/
                common(){
                    var that=this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/sizeGroupHead',
                        data: {
                            type:1,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                that.sizeGr=data.content.vertical;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*获取仓库,客户，销售季节*/
                basic(){
                    var that = this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/return-base-info',
                        data: {
                            id:'{{$id}}'
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                that.order_num=data.content.order_num;
                                that.options1=data.content.data.fact_type;//仓库
                                that.options2=data.content.data.shop_lists;
                                that.options3=data.content.data.sale_season;//季节
                                that.options4=data.content.data.customer;//客户
                                that.options5=data.content.data.deliver_type;//类型


                                that.fact_type_id=data.content.fact_type_id;
                                if(data.content.customer_type==1){
                                    that.shopShow=true;
                                    that.peopleShow=false;
                                }else if(data.content.customer_type==2){
                                    that.shopShow=false;
                                    that.peopleShow=true;
                                }
                                that.customer_type=data.content.customer_type;
                                that.customer_id=data.content.customer_id;
                                that.season=data.content.season;
                                that.season_id=data.content.season_id;
                                that.deliver_type_id=data.content.deliver_type_id;
                                that.remark=data.content.remark;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*单选改变*/
                radioCha(val){
                    if(val==1){
                        this.shopShow=true;
                        this.peopleShow=false;
                    }else if(val==2){
                        this.shopShow=false;
                        this.peopleShow=true;
                    }
                    this.customer_id='';
                    this.customer_type=val;
                },
                /*获取季节名称*/
                changeLabel(val){
                    let obj = {};
                    obj = this.options3.find((item)=>{
                        return item.id === val;
                    });
                    this.season=obj.sale_season;
                },
                /*汇总数据*/
                countBble(){
                    var that = this;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/pfth-girard-count',
                        data: {
                            id:'{{$id}}',
                            brand_1:this.brand_1,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                let optio = [];
                                let girardArr=[];
                                for(var value of data.content){
                                    if(girardArr.indexOf(value.girard)==-1){
                                        girardArr.push(value.girard)
                                    };
                                    var cvs=0;
                                    for(var cv=0;cv<value.nums.length;cv++){
                                        if(value.nums[cv]==''){
                                            value.nums[cv]=0;
                                        }
                                        cvs+=Number(value.nums[cv]);
                                    }
                                    var oneNum=0;
                                    var twoNum=0;
                                    if(value.nums.length==9 && value.price.indexOf("/")!=-1){
                                        for(var cc=0;cc<value.nums.length;cc++){
                                            if(value.nums[cc]==''){
                                                value.nums[cc]=0;
                                            }
                                            if(cc<7){
                                                oneNum+=Number(value.nums[cc]);
                                            }else{
                                                twoNum+=Number(value.nums[cc]);
                                            }
                                        }
                                    }
                                    optio.push({
                                        "brand_1":value.brand,
                                        "girard":value.girard,
                                        "cate_3":value.cate_3,
                                        "color":value.color,
                                        "size_group":value.size_group,
                                        "num":value.nums,
                                        "count":cvs,
                                        "price":value.price,
                                        "total_price":that.getCou(value.price , oneNum , twoNum , cvs),
                                    });
                                }
                                that.girardNum=girardArr.length;
                                that.countInfo = optio;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*折扣价*/
                getMon(money,dis){
                    if(money.indexOf("/")!=-1 && dis.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disArr=dis.split("/");
                        let disPriOne=(priArr[0]*disArr[0]).toFixed(2);
                        let disPriTwo=(priArr[1]*disArr[1]).toFixed(2);
                        return disPriOne+'/'+disPriTwo
                    }else if(money.indexOf("/")!=-1 && dis.indexOf("/")==-1){
                        let priArr=money.split("/");
                        let disPriOne=(priArr[0]*dis).toFixed(2);
                        let disPriTwo=(priArr[1]*dis).toFixed(2);
                        return disPriOne+'/'+disPriTwo
                    }else if(money.indexOf("/")==-1 && dis.indexOf("/")!=-1){
                        let disArr=dis.split("/");
                        let disPriOne=(money*disArr[0]).toFixed(2);
                        let disPriTwo=(money*disArr[1]).toFixed(2);
                        return disPriOne+'/'+disPriTwo
                    }else{
                        return (money*dis).toFixed(2);
                    }
                },
                /*总折扣金额*/
                getDon(money,dis,n1,n2,n3){
                    if(money.indexOf("/")!=-1 && dis.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disArr=dis.split("/");
                        let disPriOne=(priArr[0]*disArr[0]*n1);
                        let disPriTwo=(priArr[1]*disArr[1]*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else if(money.indexOf("/")!=-1 && dis.indexOf("/")==-1){
                        let priArr=money.split("/");
                        let disPriOne=(priArr[0]*dis*n1);
                        let disPriTwo=(priArr[1]*dis*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else if(money.indexOf("/")==-1 && dis.indexOf("/")!=-1){
                        let disArr=dis.split("/");
                        let disPriOne=(money*disArr[0]*n1);
                        let disPriTwo=(money*disArr[1]*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else{
                        return (money*dis*n3).toFixed(2);
                    }
                },
                /*总吊牌金额*/
                getCou(money,n1,n2,n3){
                    if(money.indexOf("/")!=-1){
                        let priArr=money.split("/");
                        let disPriOne=(priArr[0]*n1);
                        let disPriTwo=(priArr[1]*n2);
                        return (Number(disPriOne) + Number(disPriTwo)).toFixed(2);
                    }else{
                        return (money*n3).toFixed(2);
                    }
                },
                //详情数据
                grabble(type){
                    var that = this;
                    let skip;
                    if(type == 'reset'){
                        skip = 0;
                    }else{
                        skip = that.currentPage2-1;
                    }
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/distribution/pfth-scan-code-infos',
                        data: {
                            skip:skip,
                            id:'{{$id}}',
                            code:this.small_qr,
                            girard:this.girard,
                            brand_2:this.brand_2,
                        },
                        success: function (data) {
                            //console.log(data);
                            if(data.result.success){
                                if(data.content.data.length>0){
                                    that.sendType=true;
                                }else{
                                    that.sendType=false;
                                }
                                let option2 = [];
                                let i = 0;
                                for(let value of data.content.data){
                                    i++;

                                    option2.push({
                                        "loop":i+(10*skip),
                                        "small_qr":value.code,
                                        "brand_2":value.brand_2,
                                        "girard":value.girard,
                                        "cate_1":value.cate_1,
                                        "cate_2":value.cate_2,
                                        "cate_3":value.cate_3,
                                        "color":value.color,
                                        "size":value.size,
                                        "price":parseFloat(value.price).toFixed(2),
                                        "is_ack":that.is_ack,
                                    })
                                }
                                that.detailInfo = option2;
                                that.total2 = data.content.total;
                                that.currentPage2 = data.content.skip;
                            }else{
                                that.$notify.error({
                                    title: '提示',
                                    message: data.result.errorMsg,
                                });
                            }
                        }
                    });
                },
                /*重置详情*/
                resetSou(){
                    this.small_qr='';
                    this.girard='';
                    this.brand_2='';
                    this.grabble('reset');
                },
                /*详情分页*/
                changePageSkip2(val){
                    this.currentPage2 = val;
                    this.grabble();
                },
                /*汇总品牌搜索*/
                filterChange1(filters){
                    var fil=filters.brand_1;
                    var stas='';
                    for(var d=0;d<fil.length; d++){
                        stas=stas+fil[d]+',';
                    }
                    this.brand_1=stas.substr(0, stas.length - 1);
                    this.countBble();
                },
                /*详情品牌搜索*/
                filterChange2(filters){
                    var fil=filters.brand_2;
                    var stas='';
                    for(var d=0;d<fil.length; d++){
                        stas=stas+fil[d]+',';
                    }
                    this.brand_2=stas.substr(0, stas.length - 1);
                    this.grabble('reset');
                },
                /*删除条码*/
                delSmallQr(scope){
                    var that=this;
                    const h = this.$createElement;
                    this.$msgbox({
                        title: '提示',
                        message: h('p', null, [
                            h('span', null, '是否确定删除该款商品?'),
                        ]),
                        showCancelButton: true,
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        beforeClose: (action, instance, done) => {
                            if (action === 'confirm') {
                                if(that.delSmallQrFlag==true){
                                    that.delSmallQrFlag=false;
                                    $.ajax({
                                        headers: {
                                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                        },
                                        type: 'post',
                                        url: '/distribution/pfth-code-del',
                                        data: {
                                            id:'{{$id}}',
                                            code:scope.row.small_qr,
                                        },
                                        success: function (data) {
                                            //console.log(data);
                                            if(data.result.success){
                                                that.$notify.success({
                                                    title: '提示',
                                                    message: data.content
                                                });
                                                done();
                                                that.grabble('reset');
                                                that.countBble();//汇总
                                                that.delSmallQrFlag=true;
                                            }else{
                                                that.$notify.error({
                                                    title: '错误',
                                                    message: data.result.errorMsg
                                                });
                                                that.delSmallQrFlag=true;
                                            }
                                        }
                                    })
                                }
                            } else {
                                done();
                            }
                        }
                    }).then(action => {

                    });
                },
                /*制单完成*/
                overTrue() {
                    if(this.detailInfo.length<=0){
                        this.$notify.error({
                            title: '提示',
                            message: "至少添加一条数据",
                        });
                        return false;
                    }
                    if(this.fact_type_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请选择退货仓库',
                        });
                        return false;
                    }
                    if(this.customer_type==1 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择收货店铺",
                        });
                        return false;
                    }
                    if(this.customer_type==2 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择客户",
                        });
                        return false;
                    }
                    if(this.season_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请选择销售季节',
                        });
                        return false;
                    }
                    var that=this;
                    const h = this.$createElement;
                    this.$msgbox({
                        title: '提示',
                        message: h('p', null, [
                            h('span', null, '是否确定完成制单?'),
                        ]),
                        showCancelButton: true,
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        beforeClose: (action, instance, done) => {
                            if (action === 'confirm') {
                                if(that.overTrueFlag==true){
                                    that.overTrueFlag=false;
                                    $.ajax({
                                        headers: {
                                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                                        },
                                        type: 'post',
                                        url: '/distribution/pfth-complete',
                                        data: {
                                            id:'{{$id}}',
                                            is_modify:'{{$is_modify}}',
                                            fact_type_id:that.fact_type_id,
                                            customer_id:that.customer_id,
                                            customer_type:that.customer_type,
                                            season_id:that.season_id,
                                            season:that.season,
                                            remark:that.remark,
                                        },
                                        success: function (data) {
                                            if(data.result.success){
                                                that.$notify.success({
                                                    title: '提示',
                                                    message: '操作成功'
                                                });
                                                that.showBox = false;
                                                that.showFa=false;
                                                that.showCode=false;
                                                that.countBble();//汇总
                                                that.grabble('reset');//详情
                                                done();
                                                that.overTrueFlag=true;
                                                setTimeout(function () {
                                                    window.location.href='/distribution/goods-return-list';
                                                },1000)
                                            }else{
                                                that.$notify.error({
                                                    title: '错误',
                                                    message: data.result.errorMsg
                                                });
                                                that.overTrueFlag=true;
                                            }
                                        }
                                    })
                                }
                            } else {
                                done();
                            }
                        }
                    }).then(action => {

                    });
                },
                /*合计*/
                getSummaries(param) {
                    var that=this;
                    const { columns, data } = param;
                    const sums = [];
                    columns.forEach((column, index) => {
                        if (index === 0) {
                            sums[index] = '合计';
                            return;
                        }
                        const values = data.map(item => Number(item[column.property]));
                        switch (column.property) {
                            case 'girard':
                                sums[index] = that.girardNum;
                                break;
                            case 'count':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return prev + curr;
                                    } else {
                                        return prev;
                                    }
                                }, 0);
                                break;
                            case 'total_price':
                                sums[index] = values.reduce((prev, curr) => {
                                    const value = Number(curr);
                                    if (!isNaN(value)) {
                                        return ( parseFloat(prev) + parseFloat(curr) ).toFixed(2);
                                    } else {
                                        return parseFloat(prev).toFixed(2);
                                    }
                                }, 0);
                                break;
                            default:
                                break;
                        }
                    });
                    return sums
                },
                /*确认*/
                sureCode(){
                    if(this.fact_type_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请选择退货仓库',
                        });
                        return false;
                    }
                    if(this.customer_type==1 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择收货店铺",
                        });
                        return false;
                    }
                    if(this.customer_type==2 && this.customer_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: "请选择客户",
                        });
                        return false;
                    }
                    if(this.season_id==''){
                        this.$notify.error({
                            title: '提示',
                            message: '请选择销售季节',
                        });
                        return false;
                    }
                    var that=this;
                    if (this.codes != '') {
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            type: 'post',
                            url: '/distribution/pfth-scan-code',
                            data: {
                                id:'{{$id}}',
                                is_modify:'{{$is_modify}}',
                                code:this.codes,
                                fact_type_id:this.fact_type_id,
                                customer_id:this.customer_id,
                                customer_type:this.customer_type,
                                season_id:this.season_id,
                                season:this.season,
                                remark:this.remark,
                            },
                            success: function (data) {
                                if(data.result.success){
                                    that.codes='';
                                    that.countBble();//汇总
                                    that.grabble('reset');//详情
                                    var music = document.getElementById("music_success");
                                    music.play();
                                    that.$notify.success({
                                        title: '提示',
                                        message: "扫码成功"
                                    });
                                }else{
                                    var music = document.getElementById("music_faile");
                                    music.play();
                                    that.$notify.error({
                                        title: '错误',
                                        message: data.result.errorMsg
                                    });
                                }
                            }
                        })
                    }
                }
            },
            watch : {
                codes:function(val) {
                    this.codes = val;
                    var that=this;
                    if (this.codes != '' && this.codes.length==15) {
                        if(this.fact_type_id==''){
                            this.$notify.error({
                                title: '提示',
                                message: '请选择退货仓库',
                            });
                            return false;
                        }
                        if(this.customer_type==1 && this.customer_id==''){
                            this.$notify.error({
                                title: '提示',
                                message: "请选择收货店铺",
                            });
                            return false;
                        }
                        if(this.customer_type==2 && this.customer_id==''){
                            this.$notify.error({
                                title: '提示',
                                message: "请选择客户",
                            });
                            return false;
                        }
                        if(this.season_id==''){
                            this.$notify.error({
                                title: '提示',
                                message: '请选择销售季节',
                            });
                            return false;
                        }
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                            },
                            type: 'post',
                            url: '/distribution/pfth-scan-code',
                            data: {
                                id:'{{$id}}',
                                is_modify:'{{$is_modify}}',
                                code:this.codes,
                                fact_type_id:this.fact_type_id,
                                customer_id:this.customer_id,
                                customer_type:this.customer_type,
                                season_id:this.season_id,
                                season:this.season,
                                remark:this.remark,
                            },
                            success: function (data) {
                                if(data.result.success){
                                    that.codes='';
                                    that.countBble();//汇总
                                    that.grabble('reset');//详情
                                    var music = document.getElementById("music_success");
                                    music.play();
                                    that.$notify.success({
                                        title: '提示',
                                        message: "扫码成功"
                                    });
                                }else{
                                    var music = document.getElementById("music_faile");
                                    music.play();
                                    that.$notify.error({
                                        title: '错误',
                                        message: data.result.errorMsg
                                    });
                                }
                            }
                        })
                    }
                },
            }
        });
    </script>
@endsection
